/**
 * \file display.h
 * \brief Display module syscall definitions
 * \author Corey Tabaka
 */

/*
   Copyright 2007 Corey Tabaka

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#ifndef __MODULE_DISPLAY_SYSCALL_H__
#define __MODULE_DISPLAY_SYSCALL_H__

#include <syscall.h>

enum {
	SYSCALL_DISPLAY=0x1000,
};

// Subfunctions for SYSCALL_DISPLAY
enum {
	SYSCALL_DISPLAY_QUERY,
	SYSCALL_DISPLAY_GET_MODE,
	SYSCALL_DISPLAY_SET_MODE,
	SYSCALL_DISPLAY_GET_MODEINFO,
	SYSCALL_DISPLAY_DRAW_STRING,
	SYSCALL_DISPLAY_DRAW_LINE,
	SYSCALL_DISPLAY_DRAW_GRADIENT_LINE,
	SYSCALL_DISPLAY_SOLID_FILL,
	SYSCALL_DISPLAY_MAP_FRAME_BUFFER,
	SYSCALL_DISPLAY_GET_EDID,
	SYSCALL_DISPLAY_SWAP_BUFFERS,
};

typedef struct {
	int width;
	int height;
	int bpp;
	int scanWidth;
} display_modeinfo_t;


//#ifndef __IN_KERENL_MODULE__

static inline bool display_query(void) {
	return syscall32(SYSCALL_DISPLAY, SYSCALL_DISPLAY_QUERY, 0xdeadbeef)
		== 0xfeedbeef;
}

static inline void display_drawString(const char *str, sint16 x, sint16 y,
	uint32 fg, uint32 bg) {
	syscall32(SYSCALL_DISPLAY, SYSCALL_DISPLAY_DRAW_STRING, str, x, y, fg, bg);
}

static inline void display_line(sint16 x0, sint16 y0, sint16 x1, sint16 y1,
	uint32 fg) {
	syscall32(SYSCALL_DISPLAY, SYSCALL_DISPLAY_DRAW_LINE, x0, y0, x1, y1, fg);
}

static inline void display_gradientLine(sint16 x0, sint16 y0, sint16 x1, sint16 y1,
	uint32 fg, uint32 bg) {
	syscall32(SYSCALL_DISPLAY, SYSCALL_DISPLAY_DRAW_GRADIENT_LINE, x0, y0, x1,
		y1, fg, bg);
}

static inline void display_solidFill(uint32 color, sint16 x, sint16 y, uint16 w,
	uint16 h) {
	syscall32(SYSCALL_DISPLAY, SYSCALL_DISPLAY_SOLID_FILL, color, x, y, w, h);
}

static inline void display_getModeInfo(display_modeinfo_t *modeinfo) {
	syscall32(SYSCALL_DISPLAY, SYSCALL_DISPLAY_GET_MODEINFO, modeinfo);
}

static inline void * display_mapFrameBuffer(void) {
	return (void *) syscall32(SYSCALL_DISPLAY,
		SYSCALL_DISPLAY_MAP_FRAME_BUFFER);
}

static inline bool display_getEDID(void *buffer) {
	return (bool) syscall32(SYSCALL_DISPLAY, SYSCALL_DISPLAY_GET_EDID, buffer);
}

static inline bool display_swapBuffers(void) {
	return (bool) syscall32(SYSCALL_DISPLAY, SYSCALL_DISPLAY_SWAP_BUFFERS);
}

//#endif

#endif
